.TH std::unique_ptr::operatorbool 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::unique_ptr::operatorbool \- std::unique_ptr::operatorbool

.SH Synopsis
   explicit operator bool() const noexcept;  \fI(since C++11)\fP
                                             (constexpr since C++23)

   Checks whether *this owns an object, i.e. whether get() != nullptr.

.SH Parameters

   \fI(none)\fP

.SH Return value

   true if *this owns an object, false otherwise.

.SH Example


// Run this code

 #include <iostream>
 #include <memory>

 int main()
 {
     std::unique_ptr<int> ptr(new int(42));

     if (ptr)
         std::cout << "before reset, ptr is: " << *ptr << '\\n';
     ptr.reset();
     ptr ? (std::cout << "after reset, ptr is: " << *ptr)
         : (std::cout << "after reset ptr is empty") << '\\n';
 }

.SH Output:

 before reset, ptr is: 42
 after reset ptr is empty

.SH See also

   get returns a pointer to the managed object
       \fI(public member function)\fP
